getFoodInfoByIds();//获取选中菜品信息

getRestaurantInfo();//餐厅信息
//餐厅信息
function getRestaurantInfo(){

    var detailInfo = JSON.parse(sessionStorage.getItem("detailInfo"));
    var restaurantId = detailInfo.restaurantId;

	var obj = JSON.stringify({
		"id": restaurantId,
	});

	httpHelperpost(_API_GETRESTAURANT_INFO, obj, function(isSuccess, data) {
        if (isSuccess == true) {
            var response = data.responseText;
            var value = JSON.parse(response);
    			
   			// console.log(response);
            var dispatchPrice = "";
            value.data.dispatchPrice == null?dispatchPrice = 0:dispatchPrice=value.data.dispatchPrice;


   			$(".topReturn-text").text(value.data.name);
   			$("#restaurantPhone").val(value.data.phone);
            
            $(".selectLight").attr("data-dispatchPrice",value.data.dispatchPrice);

            if(value.code == 0){
             	console.log("查询成功");
             	findRestaurantDispatchList(value.data.dispatchPrice,value.data.fullReduces);//获取配送类型
                
            }else if(value.code==401){
                alert(value.message);
                window.location.href='./index.html';
            }else{
                alert(value.message);
             	console.log("查询失败");
            }
        }else {}
    });
}

//获取配送类型
function findRestaurantDispatchList(dispatchPrice,fullReduces){
	
    var detailInfo = JSON.parse(sessionStorage.getItem("detailInfo"));
    var totalPrice = detailInfo.totalPrice;
    var restaurantId = detailInfo.restaurantId;

    var totalAndDis = parseFloat(dispatchPrice)+parseFloat(totalPrice);

    //优惠券参数
    var couponName = "请选择";
    var satisfyMoney = 0;
    var reduceMoney = 0;
    var selectCoupon = sessionStorage.getItem("selectCoupon");
    if(selectCoupon==undefined||selectCoupon==""||selectCoupon==null){
    }else{
        selectCoupon = JSON.parse(selectCoupon);
        couponName = selectCoupon.couponName;
        satisfyMoney = selectCoupon.satisfyMoney;
        reduceMoney = selectCoupon.reduceMoney;
    }

    //满减优惠参数
    var fullReducesName = "暂无可用";
    var maxReduceMoney = 0;
    var fullReducesIndex = 0;
    for(var i=0;i<fullReduces.length;i++){
        if(totalAndDis>=fullReduces[i].satisfyMoney){
            if(parseFloat(fullReduces[i].reduceMoney)>maxReduceMoney){
                maxReduceMoney=fullReduces[i].reduceMoney;
                fullReducesIndex = i;
            }
        }
    }

    if(maxReduceMoney==0){
        var isOverlay = 2;
    }else{
        var isOverlay = 1;
        fullReducesName = fullReduces[fullReducesIndex].fullReduceName;
    }
    totalPrice = parseFloat(totalPrice-maxReduceMoney-reduceMoney);
    if(totalPrice<0){
        totalPrice = 0;
    }

	var obj = JSON.stringify({
		"id":restaurantId,
	});
    httpHelperpost(_API_RESTAURANT_DISPATCH, obj, function(isSuccess, data) {
        if (isSuccess == true) {
            var response = data.responseText;
            var value = JSON.parse(response);
                
            // console.log(response);
            var optionHtml = "";
            for(var i=0;i<value.data.length;i++){
                optionHtml +="<div onclick=checkOrderInfoType(this,"+value.data[i].id+"); data-typeid="+value.data[i].id+">"+value.data[i].name+"</div>";
            }
            
            $(".selectLight").html(optionHtml);
            $(".selectLight").attr("data-val",JSON.stringify(fullReduces));

            if(value.code == 0){
                console.log("查询成功");

                // var currentType = sessionStorage.getItem("currentType",currentType);

                // if(currentType==2){
                //     $(".selectLight > div:nth-child(2)").click();
                // }else if(currentType==3){
                //     $(".selectLight > div:nth-child(3)").click();
                // }else{
                //     $(".selectLight > div:nth-child(1)").click();
                // }
                
            }else if(value.code==401){
                alert(value.message);
                window.location.href='./index.html';
            }else{
                alert(value.message);
                console.log("查询失败");
            }
        }else {}
    });
}



//获取选中菜品信息
function getFoodInfoByIds(){
    var checkOrderInfo = sessionStorage.getItem("checkOrderInfo");
    checkOrderInfo = JSON.parse(checkOrderInfo);
    
    //当前优惠券是否可用判断
    var selectCoupon = sessionStorage.getItem("selectCoupon");
    if(selectCoupon==null||selectCoupon==undefined||selectCoupon==""){
    }else{
        var allPrice = checkOrderInfo.allPrice;
        if(checkOrderInfo.fullReduce==null){
        }else{
            allPrice = allPrice-checkOrderInfo.fullReduce.reduceMoney;
        }
        if(selectCoupon.satisfyMoney>allPrice){
            sessionStorage.setItem("selectCoupon","");
        }
    }

    var dispatchId = sessionStorage.getItem("currentType");

    var dispatchPrice = 0;
    if(dispatchId==2){
        dispatchPrice = $("#dispatchPrice").text();
    }
    var subHtml = "";
    for(var i=0;i<checkOrderInfo.foods.length;i++){
        subHtml +="<li data-foodId="+checkOrderInfo.foods[i].id+">"
                +"<div class='sub-root'>"
                +"<div class='sub-root-img'><img src="+checkOrderInfo.foods[i].picture+"></div>"
                +"<div class='sub-root-bar'>"
                +"<div class='sub-root-title'>"+checkOrderInfo.foods[i].name+"</div>"
                +"<div class='sub-root-type'><span class='sub-root-w'>周一至周日</span><span>免预约</span></div>"
                +"<div class='sub-root-size'><span>随时退</span><span>过期自动退</span></div>"
                +"</div>"
                +"<div class='sub-root-money'>￥<span class='price'>"+checkOrderInfo.foods[i].price+"</span></div>"
                +"</div>"
                +"<div class='sub-num pd'>"
                +"<span class='sub-title'>数量</span>"
                +"<span class='foodNum'>"+checkOrderInfo.foods[i].buyNum+"</span>"
                +"</div>"
                +"</li>";
    }
    $("#subUl").html(subHtml);
    $("#totalPrice").text(checkOrderInfo.allPrice);

    // if(checkOrderInfo.fullReduce==null||checkOrderInfo.fullReduce==undefined||checkOrderInfo.fullReduce==""){

    //     var html ="<div class='sub-vouchers pd'>"
    //             +"<span class='sub-title'>满减优惠</span><div class='sub-select'><span>暂无可用</span></div>"  
    //             +"</div>"
    //             +"<div id='subCouponInc' class='sub-vouchers pd'>"
    //             +"<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(checkOrderInfo.factPrice)+parseFloat(dispatchPrice))+",2);>请选择</span><img src='./img/return_01.png'></div>"  
    //             +"</div>";
    // }else{
        
    //     var html ="<div class='sub-vouchers pd'>"
    //             +"<span class='sub-title'>满减优惠</span><div class='sub-select'><span>"+checkOrderInfo.fullReduce.fullReduceName+"</span></div>"  
    //             +"</div>"
    //             +"<div id='subCouponInc' class='sub-vouchers pd'>"
    //             +"<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(checkOrderInfo.factPrice)+parseFloat(dispatchPrice))+",1);>请选择</span><img src='./img/return_01.png'></div>"  
    //             +"</div>";

                
    // }
    //     html+="<div class='sub-realMoney pd'>"
    //             +"<span class='sub-title'>实付金额</span><span class='sub-money'>￥<span id='realMoney'>"+checkOrderInfo.factPrice+"</span></span>"
    //         +"</div>";
    // $("#subInfor").after(html);
    // $(".sub-order").text("￥"+checkOrderInfo.factPrice+"提交订单");
    checkOrderInfoCou(dispatchId);//订单-确认订单信息(修改优惠券)
}

//订单-确认订单信息(切换配送类型)
function checkOrderInfoType(that,dispatchId){
    var isAddress = true;
    var checkOrderObj = JSON.parse(sessionStorage.getItem("checkOrderObj"));
    
    var selectCoupon =sessionStorage.getItem("selectCoupon");

    if(selectCoupon==null||selectCoupon==undefined||selectCoupon==""){
        var userCouponId = "";
    }else{
        selectCoupon = JSON.parse(selectCoupon);
        var userCouponId = selectCoupon.id;
    }
    
    var extra = {userCouponId:userCouponId};
    var foodList = checkOrderObj.foodList;
    var restaurantId = checkOrderObj.restaurantId;
    var restaurantName = checkOrderObj.restaurantName;
    var restaurantPhone = checkOrderObj.restaurantPhone;
    var userPhone = checkOrderObj.userPhone;

    if(dispatchId==2){
        var addressId = localStorage.getItem("selectAddressId");
        // if(addressId==null||addressId==undefined||addressId==""){
        //     alert("请选择地址");
        //     isAddress = false;
        // }else{
            isAddress = true;
            var obj = JSON.stringify({
                "addressId": addressId,
                "dispatchId": dispatchId,
                "foodList":foodList,
                "restaurantId":restaurantId,
                "restaurantName":restaurantName,
                "restaurantPhone":restaurantPhone,
                "extra": extra,
                "userPhone":userPhone
            });
        // }
    }else{
        var obj = JSON.stringify({
            "dispatchId": dispatchId,
            "foodList":foodList,
            "restaurantId":restaurantId,
            "restaurantName":restaurantName,
            "restaurantPhone":restaurantPhone,
            "extra": extra,
            "userPhone":userPhone
        });

    }
    
    if(isAddress==true){
        httpHelperpost("/api/foodOrders/checkOrderInfo", obj, function(isSuccess, data) {
            if (isSuccess == true) {
                var response = data.responseText;
                var value = JSON.parse(response);
                    
                console.log(response);
                
                if(value.code == 0){
                    console.log("查询成功");
                    var typeHtml = "";
                    var reduceMoney = 0;
                    var couponName = "请选择";
                    var couponHtml = "";
                    var isfullReduce = true;
                    if(value.data.fullReduce==null||value.data.fullReduce==undefined||value.data.fullReduce==""){
                        isfullReduce = false;
                    }else{
                        reduceMoney = value.data.fullReduce.reduceMoney;
                    }
                    
                    if(dispatchId==1){
                        typeHtml ="<div class='sub-phone pd'>"
                            +"<span class='sub-title'>手机号</span>"
                            +"<input class='sub-phone-num' type='text' value="+value.data.userPhone+">"
                            +"</div>";
                            
                            if(isfullReduce==true){
                                couponHtml = "<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney))+",1);>请选择</span><img src='./img/return_01.png'></div>";
                            }else{
                                couponHtml = "<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney))+",2);>请选择</span><img src='./img/return_01.png'></div>";
                            }
                            
                    }else if(dispatchId==2){
                        var phone = value.data.userPhone;
                        var address = "请选择";
                        if(value.data.userAddressDTO==null||value.data.userAddressDTO==undefined||value.data.userAddressDTO==""){
                        }else{
                            phone = value.data.userAddressDTO.phone;
                            address = value.data.userAddressDTO.address;
                        }
                        typeHtml ="<div class='sub-phone pd'>"
                            +"<span class='sub-title'>手机号</span>"
                            +"<input class='sub-phone-num' type='text' value="+phone+">"
                            +"</div>"
                            +"<div class='sub-realMoney pd'>"
                            +"<span class='sub-title'>配送费</span><span class='sub-money'>￥<span id='dispatchPrice'>"+value.data.dispatchPrice+"</span></span>"
                            +"</div>"
                            +"<div class='sub-vouchers pd'>"
                            +"<span class='sub-title'>选择地址</span><div onclick='selectAddress(0);' class='sub-select'><span id='subAddress'>"+address+"</span><img src='./img/return_01.png'></div>"  
                            +"</div>";

                            if(isfullReduce==true){
                                couponHtml ="<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney)+parseFloat(value.data.dispatchPrice))+",1);>请选择</span><img src='./img/return_01.png'></div>";
                            }else{
                                couponHtml ="<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney)+parseFloat(value.data.dispatchPrice))+",2);>请选择</span><img src='./img/return_01.png'></div>"
                            }
                            
                    }else if(dispatchId==3){
                        typeHtml ="<div class='sub-phone pd'>"
                            +"<span class='sub-title'>手机号</span>"
                            +"<input class='sub-phone-num' type='text' value="+value.data.userPhone+">"
                            +"</div>";
                            if(isfullReduce==true){
                                couponHtml = "<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney))+",1);>请选择</span><img src='./img/return_01.png'></div>";
                            }else{
                                couponHtml = "<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney))+",2);>请选择</span><img src='./img/return_01.png'></div>";
                            }
                    }
                    $("#subCouponInc").html(couponHtml);//添加优惠券字段

                    zhezhaoNo();
                    $("#selTypeName").text($(that).text());
                    $("#selTypeInc .sub-select").attr("data-typeid",dispatchId);
                    $("#subInfor").html(typeHtml);

                    $("#realMoney").text(value.data.factPrice);
                    $(".sub-order").text("￥"+value.data.factPrice+"提交订单");
                }else if(value.code==401){
                    alert(value.message);
                    window.location.href='./index.html';
                }else{
                    alert(value.message);
                    console.log("查询失败");
                }
            }else {}
        });
    }
}

//订单-确认订单信息(修改优惠券)
function checkOrderInfoCou(dispatchId){
    var selectCoupon =sessionStorage.getItem("selectCoupon");

    if(selectCoupon==null||selectCoupon==undefined||selectCoupon==""){
        var userCouponId = "";
    }else{
        selectCoupon = JSON.parse(selectCoupon);
        var userCouponId = selectCoupon.id;
    }
    var extra = {userCouponId:userCouponId};

    var checkOrderObj = JSON.parse(sessionStorage.getItem("checkOrderObj"));
    
    var foodList = checkOrderObj.foodList;
    var restaurantId = checkOrderObj.restaurantId;
    var restaurantName = checkOrderObj.restaurantName;
    var restaurantPhone = checkOrderObj.restaurantPhone;
    var userPhone = checkOrderObj.userPhone;
    var addressId = localStorage.getItem("selectAddressId");

    if(dispatchId==""||dispatchId==null||dispatchId==undefined){
        dispatchId=1;
    }
    var obj = JSON.stringify({
        "dispatchId": dispatchId,
        "foodList":foodList,
        "restaurantId":restaurantId,
        "restaurantName":restaurantName,
        "restaurantPhone":restaurantPhone,
        "extra": extra,
        "userPhone":userPhone,
        "addressId":addressId
    });
    
    httpHelperpost("/api/foodOrders/checkOrderInfo", obj, function(isSuccess, data) {
        if (isSuccess == true) {
            var response = data.responseText;
            var value = JSON.parse(response);
            
            // console.log(response);

            if(value.code == 0){//假如一切正常
                console.log("查询成功");
                
            }else if(value.code==401){
                alert(value.message);
                window.location.href='./index.html';
            }else{//假如优惠券返回空
                alert(value.message);
                console.log("查询失败");
            }

            var reduceMoney = 0;
            var typeHtml = "";
            var reduceMoney = 0;
            var couponName = "请选择";
            var couponHtml = "";
            var isfullReduce = true;
            var userCoupon = 0;

            if(value.data.fullReduce==null||value.data.fullReduce==undefined||value.data.fullReduce==""){
                    
            }else{
                reduceMoney = value.data.fullReduce.reduceMoney;
            }

            if(value.data.fullReduce==null||value.data.fullReduce==undefined||value.data.fullReduce==""){
                    
                    var html ="<div class='sub-vouchers pd'>"
                            +"<span class='sub-title'>满减优惠</span><div class='sub-select'><span>暂无可用</span></div>"  
                            +"</div>"
                            +"<div id='subCouponInc' class='sub-vouchers pd'>"
                            +"<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.factPrice)+parseFloat(value.data.dispatchPrice))+",2);>请选择</span><img src='./img/return_01.png'></div>"  
                            +"</div>";
                }else{
                    
                    var html ="<div class='sub-vouchers pd'>"
                            +"<span class='sub-title'>满减优惠</span><div class='sub-select'><span>"+value.data.fullReduce.fullReduceName+"</span></div>"  
                            +"</div>"
                            +"<div id='subCouponInc' class='sub-vouchers pd'>"
                            +"<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.factPrice)+parseFloat(value.data.dispatchPrice))+",1);>请选择</span><img src='./img/return_01.png'></div>"  
                            +"</div>";
            
                      
                }
                    html+="<div class='sub-realMoney pd'>"
                            +"<span class='sub-title'>实付金额</span><span class='sub-money'>￥<span id='realMoney'>"+value.data.factPrice+"</span></span>"
                        +"</div>";
                
                $("#subInfor").after(html);
                $(".sub-order").text("￥"+value.data.factPrice+"提交订单");

                
                if(value.data.fullReduce==null||value.data.fullReduce==undefined||value.data.fullReduce==""){
                    isfullReduce = false;
                }
                // var phone = ;
                if(value.data.userCoupon==null||value.data.userCoupon==undefined||value.data.userCoupon==""){
                    
                }else{
                    couponName = value.data.userCoupon.couponName;
                    userCouponId = value.data.userCoupon.id;
                }
                
                if(value.data.dispatchId==2){
                    
                    var address = "请选择";

                    if(value.data.userAddressDTO==null||value.data.userAddressDTO==undefined||value.data.userAddressDTO==""){
                    }else{
                        phone = value.data.userAddressDTO.phone;
                        address = value.data.userAddressDTO.address;
                    }
                    typeHtml ="<div class='sub-phone pd'>"
                        +"<span class='sub-title'>手机号</span>"
                        +"<input class='sub-phone-num' type='text' value="+value.data.userPhone+">"
                        +"</div>"
                        +"<div class='sub-realMoney pd'>"
                        +"<span class='sub-title'>配送费</span><span class='sub-money'>￥<span id='dispatchPrice'>"+value.data.dispatchPrice+"</span></span>"
                        +"</div>"
                        +"<div class='sub-vouchers pd'>"
                        +"<span class='sub-title'>选择地址</span><div onclick='selectAddress(0);' class='sub-select'><span id='subAddress'>"+address+"</span><img src='./img/return_01.png'></div>"  
                        +"</div>";
                        if(isfullReduce==true){
                            couponHtml ="<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' data-id='"+userCouponId+"' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney)+parseFloat(value.data.dispatchPrice))+",1);>"+couponName+"</span><img src='./img/return_01.png'></div>";
                        }else{
                            couponHtml ="<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney)+parseFloat(value.data.dispatchPrice))+",2);>"+couponName+"</span><img src='./img/return_01.png'></div>"
                        }
                    $("#selTypeName").text("外卖");
                }else{
                    typeHtml ="<div class='sub-phone pd'>"
                            +"<span class='sub-title'>手机号</span>"
                            +"<input class='sub-phone-num' type='text' value="+value.data.userPhone+">"
                            +"</div>";

                            if(isfullReduce==true){
                                couponHtml = "<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' data-id='"+userCouponId+"' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney))+",1);>"+couponName+"</span><img src='./img/return_01.png'></div>";
                            }else{
                                couponHtml = "<span class='sub-title'>优惠券</span><div class='sub-select'><span id='subCoupon' onclick=selectAddress(1,"+(parseFloat(value.data.allPrice)-parseFloat(reduceMoney))+",2);>"+couponName+"</span><img src='./img/return_01.png'></div>";
                            }
                    if(value.data.dispatchId==3){
                        $("#selTypeName").text("自取");
                    }else{
                        $("#selTypeName").text("食堂");
                    }
                }
                // console.log(typeHtml);
                $("#selTypeInc .sub-select").attr("data-typeid",value.data.dispatchId);
                $("#subCouponInc").html(couponHtml);//添加优惠券字段
                $("#subInfor").html(typeHtml);

            
        }else {}
    });
}

//(提交)确认订单
function addFoodOrder(dispatchId){
    var checkOrderInfo = JSON.parse(sessionStorage.getItem("checkOrderInfo"));
    var resId = checkOrderInfo.foods[0].restaurantId;
	
	
	var addressId = localStorage.getItem("selectAddressId");
	
	var foodList = [];

	for(var i=0;i<$("#subUl li").length;i++){
		list = {buyNum:$("#subUl li").eq(i).find(".foodNum").text(),id:$("#subUl li").eq(i).attr("data-foodid"),price:$("#subUl li").eq(i).find(".price").text(),restaurantId:resId};
		foodList.push(list);
	}

	var restaurantName = $(".topReturn-text").text();
	var restaurantPhone = $("#restaurantPhone").val();
	var userPhone = $(".sub-phone-num").val();
    var userCouponId = $("#subCoupon").attr("data-id");
    var extra = {userCouponId:userCouponId};

	var obj = JSON.stringify({
		"addressId":addressId,
		"dispatchId":dispatchId,
		"foodList":foodList,
		"restaurantId":resId,
		"restaurantName":restaurantName,
		"restaurantPhone":restaurantPhone,
        "userPhone":userPhone,
        "extra":extra
	});

	httpHelperpost(_API_ADD_FOOD_ORDER, obj, function(isSuccess, data) {
        if (isSuccess == true) {
            var response = data.responseText;
            var value = JSON.parse(response);
                
            console.log(response);
            
            if(value.code == 0){
                $(".zhezhao").css("display","block");
                $(".light").css("display","block");
                console.log("创建订单成功");
                
                var id = value.data;
                $(".payLight_sure").click(function(){
                    if($(".payLight_panel input").val()==""){
                        alert("请输入密码");
                    }else if($(".payLight_panel input").val()!="123456"){
                        window.location.href = "./foodAuditSF.html?status="+1;
                        // alert("密码错误，支付失败");
                    }else{
                        foodOrderSyncNotify(id);
                        // alert("支付成功");
                    }
                    
                });
                
                $(".zhezhao").click(function(){
                    window.location.href = "./foodAuditSF.html?status="+1;
                });
            }else if(value.code==401){
                alert(value.message);
                window.location.href='./index.html';
            }else{
                alert(value.message);
                console.log("创建订单失败");
            }
        }else {}
    });
}

//支付同步通知
function foodOrderSyncNotify(id){
    
    var obj = JSON.stringify({
        "id":id
    });
    httpHelperpost(_API_FOOD_ORDER_SYNC_NOTIFY, obj, function(isSuccess, data) {
        if (isSuccess == true) {
            var response = data.responseText;
            var value = JSON.parse(response);
                
            console.log(response);
            
            var status = 2;
            if(value.code == 0){
                console.log("支付成功");
                sessionStorage.setItem("detailInfo","");
                sessionStorage.setItem("selectCoupon","");
                window.location.href = "./foodAuditSF.html?status="+status;
            }else if(value.code==401){
                alert(value.message);
                window.location.href='./index.html';
            }else{
                alert(value.message);
                console.log("支付失败");
                status = 1;
                window.location.href = "./foodAuditSF.html?status="+status;
            }
        }else {}
    });
}

//携带数据返回上一级页面
function returnDetail(){
    sessionStorage.setItem("selectCoupon","");
    var detailInfo = JSON.parse(sessionStorage.getItem("detailInfo"));
    // var restaurantId = detailInfo.restaurantId;
    var Request = GetRequest();
    var restaurantId = Request['restaurantId'];
    window.location.href = "./detail.html?id="+restaurantId;
}

//选择地址或优惠券函数
function selectAddress(index,satisfyMoney,isOverlay){
    sessionStorage.setItem("currentType",$("#selTypeInc .sub-select").attr("data-typeid"));

    if(index==0){
        window.location.href = "./address.html?select="+true;
    }else if(index==1){
        var detailInfo = JSON.parse(sessionStorage.getItem("detailInfo"));
        // var restaurantId = detailInfo.restaurantId;
        var Request = GetRequest();
        var restaurantId = Request['restaurantId'];
        window.location.href = "./couponMy.html?select="+true+"&satisfyMoney="+satisfyMoney+"&isOverlay="+isOverlay+"&restaurantId="+restaurantId;
    }
    
}

//提交订单逻辑
function subOrder(){
    var dispatchId = $(".sub-select").attr("data-typeid");

    if(dispatchId == 2){
        if($("#subAddress").text()==""||$("#subAddress").text()=="请选择"){
            alert("请选择地址");
        }else{

            addFoodOrder(dispatchId);
        }
    }else{
        addFoodOrder(dispatchId);
    }
     
}

//选择类型弹出框
function subselect(){
    $(".zhezhao").css("display","block");
    $(".selectLight").css("display","block");
}
function zhezhaoNo(){
    $(".zhezhao").css("display","none");
    $(".selectLight").css("display","none");
    $(".payLight").css("display","none");
}

//获取url中"?"符后的字串
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串   
    
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      
      strs = str.split("&");
      
      for (var i = 0; i < strs.length; i++) {
        
        theRequest[strs[i].split("=")[0]] = strs[i]
            .split("=")[1];
      }
    }
    return theRequest;
}


	